﻿using B.S.Meeting.Infrastructure.Interfaces;
using CSRedis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Meeting.Infrastructure.Implements
{
    public class RedisGetList<T>:IRedisGetList<T> where T : class
    {
        CSRedisClient redisClient;
        public RedisGetList(CSRedisClient redisClient)
        {
            this.redisClient = redisClient;
        }

        public async Task<IList<T>> GetList(string key, Func<Task<IList<T>>> func, int time)
        {
            var redisInfo = await redisClient.GetAsync<IList<T>>(key);
            if (redisInfo != null)
            {
                return redisInfo;
            }
            var list = await func();
            await redisClient.SetAsync(key, list, time);
            return list;
        }
    }
}
